package cc.vv.baselibrary.util;

import android.text.TextUtils;

import cc.vv.lklibrary.log.LogOperate;

/**
 * 伯通公共Request和Result的Code 处理工具类
 * Created by PC on 2018/4/10.
 */

public class BTRequestAndResultCodeUtil {

    /** String字符转换Int类型*/
    public static final int stringConversionInt(String str) {
        int strInt = 0;
        if (TextUtils.isEmpty(str)) {
            return strInt;
        }
        char[] chars = str.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            int charInt = 0;
            try {
                charInt = (int) chars[i];
            } catch (Exception e) {
                e.printStackTrace();
            }
            if(charInt<0){
                charInt = -charInt;
            }
            strInt += charInt;
        }
        LogOperate.e(str+"_Int:" + strInt);
        if (strInt >= 65535) {
            try {
                strInt = Integer.parseInt((String.valueOf(strInt)).substring(0, 3));
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
        }
        return strInt;
    }

    /** Request和Result的Code的一致性判断*/
    public static boolean isRequestAndResultCodeMatching(int requestCode,int requestCodeValue,int resultCode,int resultCodeValue){
        return (requestCode == requestCodeValue) && (resultCode == resultCodeValue);
    }
}
